SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Alter Procedure [dbo].[spChinhSuaDatCho](@temp int, @maDatCho int, @maKH int, @ngayDat datetime, @ngayDen datetime, @tinhTrang string(10), @soLuong int, @maNH int)
As
Begin
	If @temp = 0
		Delete From DatCho
		Where MaDatCho = @maDatCho
	Else
		Begin
			If @maDatCho = 0
			Insert Into DatCho
			(
				MaDatCho,
				MaKH,
				NgayDat,
				NgayDen,
				TinhTrang,
				SoLuongNguoi,
				MaNH
			)
			Values
			(
				@maDatCho,
				@maKH,
				@ngayDat,
				@ngayDen,
				@tinhTrang,
				@soLuong,
				@maNH
			)
			Else
				Update DatCho
				Set
					MaDatCho = @maDatCho,
					MaKH = @maKH,
					NgayDat = @ngayDat,
					NgayDen = @ngayDen,
					TinhTrang = @tinhTrang,
					SoLuongNguoi = @soLuong,
					MaNH = @maNH
		End
End
